<%--
  Created by IntelliJ IDEA.
  User: qjqe@outlook.com
  Date: 2020/5/15
  Time: 9:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@page import="java.util.List"%>
<script>

    //重新刷新
    function reload() {
        location.reload();
    }
    /*修改
    点击之后页面变成可提交状态*/
    function xiugai(a){
        var trobj = a.parentNode.parentNode; //获得按钮所在行的行对象
        var tdobj = trobj.getElementsByTagName("td");
        for(var i =0;i<tdobj.length;i++){

                tdobj[i].innerHTML = "<input class='edit" + i + "'  style='max-width: 100px;' onblur='submit()' type=\"input\" value=" + tdobj[i].innerText + "  />";

        }
    }


    //点击同意按钮后的
    function tongyi(a){

            $.ajax(
                {
                    url: "/applies/status",
                    type: "post",
                    datatype:"json",
                    data:{"id":a,"status":1},
                    success: function (result) { //返回的结果自动放在resut里面了
                        if (result.status == "success") {//请求成功
                            alert("成功");
                            location.reload();
                        } else {
                            alert("失败");
                            location.reload();
                        }
                    }
                });

        }
    //点击同意按钮后的
    function no(a){

        $.ajax(
            {
                url: "/applies/status",
                type: "post",
                datatype:"json",
                data:{"id":a,"status":0},
                success: function (result) { //返回的结果自动放在resut里面了
                    if (result.status == "success") {//请求成功
                        alert("成功");
                        location.reload();
                    } else {
                        alert("失败");
                        location.reload();
                    }
                }
            });

    }

    //插入功能里的提交数据
    function add() {


        $.ajax(
            {
                url: "/student/add",
                type: "post",
                datatype:"json",
                data:{"studentid":studentid,"password":password,"email":email,"name":name,"gender":gender,"major":major,"phonenumber":phonenumber,"position":position},
                success: function (result) { //返回的结果自动放在resut里面了

                    if (result.status == "success") {//请求成功
                        alert("成功");
                        location.reload();
                    } else {
                        alert("失败");
                        location.reload();
                    }
                }
            });
    }
</script>

<h2 class="sub-header">申请列表</h2>
<div class="table-responsive">
    <table class="table table-striped">
        <thead>
        <tr>
            <th>学号</th>
            <th>名字</th>
            <th>邮箱</th>
            <th>专业</th>
            <th>住址</th>
            <th>电话号码</th>
            <th>申请部门</th>
            <th>申请理由</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items = "${requestScope.list}" var="list">
            <tr>
                <td >${list.id }</td>
                <td >${list.name }</td>
                <td >${list.email }</td>
                <td >${list.zhuanye }</td>
                <td >${list.dizhi }</td>
                <td >${list.phonenumber }</td>
                <td >${list.bumen }</td>
                <td >${list.liyou }</td>
                <th><button class="btn btn-default" onclick="tongyi(${list.appid})">同意</button></th>
                <th><button class="btn btn-default delete" onclick="no(${list.appid})">驳回</button></th>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>